from selenium import webdriver
from time import sleep
from lxml import etree

url = 'https://space.bilibili.com/19286458/video'
driver = webdriver.Chrome()
driver.get(url)
sleep(2)
html_str = driver.page_source
# print(html_str)

html = etree.HTML(html_str)
# print(html)
lis = html.xpath('.//ul[@class="clearfix cube-list"]/li')
# print(len(lis), lis)

for li in lis:
    item = {}
    item['title'] = li.xpath('./a[2]/@title')
    item['link'] = li.xpath('./a[2]/@href')
    item['bvid'] = li.xpath('./@data-aid')
    item['duration'] = li.xpath('.//span[@class="length"]/text()')
    item['play'] = li.xpath('.//span[@class="play"]/span/text()')
    # normalize-space(): 将解析的列表内容，保留第一个元素，并且剔除不可见字符
    item['pubdate'] = li.xpath('normalize-space(.//span[@class="time"]/text())')
    item['element_str'] = etree.tounicode(li)

    print(item)

driver.quit()